<template>
  <div class="integralShiftIndex">
    <c-title :text="pageTitle">
      <div slot="edit" @click="toUrl">{{ otherParams.jump_name }}</div>
    </c-title>
    <div class="tabBox" v-if="page_list.length > 0">
      <van-tabs v-model="active" @change="tabsChange" line-width="30px">
        <van-tab v-for="(item, index) in page_list" :key="index" :title="item.title"></van-tab>
      </van-tabs>
    </div>
    <div class="background_box" v-if="page_list.length > 0">
      <div class="left">
        <div class="txt">
          <div class="ttxt">{{ page_list[active].title }}</div>
          <i class="iconfont icon-bc_pay_discount"></i>
        </div>
        <div class="price" v-if="info.statistics">￥{{ info.statistics.pool_grand_amount }}</div>
      </div>
      <div class="posImg">
        <img src="https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image%2FintegralShiftIndexBG%402x.png" alt="" />
      </div>
    </div>
    <div class="detailBox">
      <div class="detail">
        <div class="detail_line">
          <div class="top" v-if="info.statistics">{{ info.statistics.pool_lock_amount }}</div>
          <div class="bottom">未{{ lock_name }}{{ integral_name }}</div>
        </div>
        <div class="detail_line">
          <div class="top" v-if="info.statistics">{{ info.statistics.pool_unlock_amount }}</div>
          <div class="bottom">已{{ lock_name }}{{ integral_name }}</div>
        </div>
      </div>
      <div class="entry" @click="toRecord">
        <div class="entry_left">
          <i class="iconfont icon-duihuanjilu"></i>
          <div class="txt">兑换记录</div>
        </div>
        <div class="entry_right">
          <i class="iconfont icon-icon_more11"></i>
        </div>
      </div>
    </div>
    <!-- <div class="posBtn" @click="toUrl">
      <i class="iconfont icon-tiaozhuanlianjie"></i>
    </div> -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      page_list: [],
      otherParams: [],
      active: 0,
      info: [],
      pageTitle: ""
    };
  },
  components: {},
  activated() {
    console.log(this.$route.query)
    if(this.$route.query.ind){
      this.active = this.$route.query.ind;
    }else{
      this.active = 0;
    }
    this.getData();
  },
  methods: {
    toRecord() {
      this.$router.push(this.fun.getUrl("integralShiftRecord", { pool_id: this.page_list[this.active].id },{ind:this.active}));
    },
    tabsChange() {
      this.getRecord(this.page_list[this.active].id);
    },
    toUrl() {
      window.location.href = this.otherParams.jump_url;
    },
    getData() {
      $http
        .post("plugin.integral-shift.frontend.modules.pool.controllers.list.index", {}, ".")
        .then(res => {
          if (res.result == 1) {
            this.page_list = res.data.page_list;
            this.otherParams = res.data.otherParams;
            this.pageTitle = `${res.data.otherParams.plugin_name}`;
            this.fun.setWXTitle(this.pageTitle);
            // this.active = 0;
            console.log(this.active,'ddddddddddd')
            this.getRecord(res.data.page_list[this.active].id);
          } else {
            this.$toast(res.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    getRecord(id) {
      $http
        .post("plugin.integral-shift.frontend.modules.detail.controllers.page.index", { pool_id: id }, ".")
        .then(res => {
          if (res.result == 1) {
            this.lock_name = res.data.otherParams.lock_name;
            this.integral_name = res.data.otherParams.integral_name;
            this.info = res.data;
          } else {
            this.$toast(res.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.tabBox {
  padding-top: 0.38rem;
  padding-bottom: 0.38rem;
  background: #fff;
}
.posBtn {
  position: fixed;
  top: 29rem;
  right: 0.75rem;
  border-radius: 50%;
  box-shadow: 0rem 0rem 0rem rgba(145, 145, 145, 0.16);
  width: 2.75rem;
  height: 2.75rem;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  .icon-tiaozhuanlianjie {
    font-size: 1.7rem;
  }
}
.background_box {
  display: flex;
  justify-content: space-between;
  height: 8.5rem;
  color: #382c0a;
  background-color: #fff;
  background: linear-gradient(180deg, #f15353 0%, #f15353 70%, #f5f5f5 100%);
  .left {
    flex: 1;
    padding-left: 0.94rem;
    padding-top: 0.9rem;
    box-sizing: border-box;
    text-align: left;
    overflow: hidden;
    .txt {
      font-size: 0.94rem;
      display: flex;
      align-items: center;
      color: #ffffff;
      .ttxt {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .price {
      font-size: 1.81rem;
      line-height: 1.8rem;
      color: #ffffff;
      font-weight: bold;
      margin-top: 0.94rem;
    }
  }
  .posImg {
    flex-shrink: 0;
    padding-top: 1.81rem;
    img {
      width: 100%;
      width: 6.63rem;
      height: 6.62rem;
      border-radius: 50%;
    }
  }
}
.detailBox {
  position: relative;
  margin: 0 0.75rem;
  margin-top: -2.4rem;
  overflow: hidden;
  .entry {
    margin-top: 0.63rem;
    border-radius: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    box-sizing: border-box;
    background: #fff;
    .entry_left {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      .icon-duihuanjilu {
        font-size: 1.2rem;
      }
      .txt {
        margin-left: 0.56rem;
        font-size: 0.88rem;
        color: #00001c;
      }
    }
    .entry_right {
      flex-shrink: 0;
      .icon-icon_more11 {
        font-size: 1rem;
        color: #aaaab3;
      }
    }
  }
  .detail {
    background: #fff;
    border-radius: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .detail_line {
      padding: 1.09rem;
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .top {
        font-size: 0.94rem;
        line-height: 0.94rem;
        color: #00001c;
        font-weight: bold;
      }
      .bottom {
        margin-top: 0.44rem;
        font-size: 0.75rem;
        color: #6e6e79;
      }
    }
  }
}
</style>
